<?php
/**
 * DouPHP
 * --------------------------------------------------------------------------------------------------
 * 版权所有 2013-2020 漳州豆壳网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.douphp.com
 * --------------------------------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在遵守授权协议前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 * 授权协议: http://www.douphp.com/license.html
 * --------------------------------------------------------------------------------------------------
 * Author: DouCo
 * Release Date: 2019-01-08
 */
if (!defined('IN_DOUCO')) {
    die('Hacking attempt');
}

$class_array = get_class_list();
foreach ($class_array as $key => $row) {
    $box_list[$key] = $box_list[$row['class_unique_id']] = get_box_list($row['class_unique_id']);
}

// 赋值给模板
$smarty->assign('box_list', $box_list);

/**
 * +----------------------------------------------------------
 * 获取内容盒子分组
 * +----------------------------------------------------------
 */
function get_class_list($class_unique_id = '') {
    $class_list_array = $GLOBALS['dou']->get_no_repeat_value('box', 'class_unique_id');
    foreach ($class_list_array as $row) {
        $class_list[] = array (
                "class" => $GLOBALS['dou']->get_one("SELECT class FROM " . $GLOBALS['dou']->table('box') . " WHERE class_unique_id = '" . $row['value'] . "'"),
                "class_unique_id" => $row['value'],
                "cur" => $row['value'] == $class_unique_id ? true : false
        );
    }
    
    return $class_list;
}
    
/**
 * +----------------------------------------------------------
 * 获取内容盒子列表
 * +----------------------------------------------------------
 */
function get_box_list($class_unique_id = '') {
    $where = $class_unique_id ? " WHERE class_unique_id = '$class_unique_id'" : ''; // 分组
    
    $sql = "SELECT * FROM " . $GLOBALS['dou']->table('box') . $where . " ORDER BY sort ASC, id ASC";
    $query = $GLOBALS['dou']->query($sql);
    while ($row = $GLOBALS['dou']->fetch_array($query)) {
        $box_list[] = array (
                "id" => $row['id'],
                "class" => $row['class'],
                "name" => $row['name'],
                "text" => $row['text'],
                "link" => $row['link'],
                "image" => $GLOBALS['dou']->dou_file($row['image']),
                "sort" => $row['sort'] 
        );
    }
    
    return $box_list;
}

?>